package com.eims.sls_app.fragment;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.android.volley.toolbox.MySingleton;
import com.android.volley.toolbox.RequestParams;
import com.eims.sls_app.dataaccess.CircleBean;
import com.eims.sls_app.dataaccess.CircleBean.CommentBean;
import com.eims.sls_app.dataaccess.CircleBean.SchemeinfoBean;
import com.eims.sls_app.dataaccess.CircleBean.SchemeinfoBean.InformationIdBean;
import com.eims.sls_app.dataaccess.CircleBean.TopicBean;
import com.eims.sls_app.dataaccess.LotteryContent;
import com.eims.sls_app.dataaccess.Schemes;
import com.eims.sls_app.dataaccess.utils.HttpUtils;
import com.eims.sls_app.protocol.RspBodyBaseBean;
import com.eims.sls_app.ui.MyCommonLotteryInfo_jc_other;
import com.eims.sls_app.ui.MyCommonLotteryInfo_other;
import com.eims.sls_app.ui.MyinfoListActivity;
import com.eims.sls_app.ui.adapter.CircleAdapter;
import com.eims.sls_app.utils.App;
import com.eims.sls_app.utils.AppTools;
import com.eims.sls_app.utils.LotteryUtils;
import com.eims.sls_app.view.MyToast;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode;
import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener2;
import com.handmark.pulltorefresh.library.PullToRefreshListView;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import bls.juejin.cn.R;
import progressBar.ProgressDialogBar;

public class CircleFragment_cirFrament extends Fragment {
	private String TAG = "CircleFragment";
	private Activity activity;
	private PullToRefreshListView circle_item_listView;
	private TextView circle_item_hint;
	private String opt, auth,info, time, imei, crc; // 格式化后的参数
	private String userId;
	private MyHandler mHandler;
	private MyAsynTask mMyAsynTask;
	private MySingleton mySingleton;
	private CircleBean circleBean;
	private InformationIdBean informationIdBean;
	private CircleAdapter circleAdapter;
	private boolean isToFirst=true;
	
	private String getopt = "46"; // 格式化后的 opt

	private String getauth, getinfo, gettime, getimei, getcrc,getkey; // 格式化后的参数
	private int getInfoPosition;
	Schemes scheme;
	private String JinECost; // 金额消费
	private String CaiJinCost;// 彩金消费
	private String reMainCaiJin;// 剩余彩金
	private boolean isJoin=true;
	List<InformationIdBean> informationIdBeans;
	private getMyHandler getMyHandler;
	private ProgressDialog pd;
	
	private LinearLayout lrInfoShow;
	private TextView tvInfoShow;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_circle_zq_circle, container, false);
		activity = getActivity();
		SharedPreferences myAhare =activity.getSharedPreferences("pinglun", Activity.MODE_PRIVATE);
		// 实例化SharedPreferences.Editor对象（第二步）
		SharedPreferences.Editor editor = myAhare.edit();
		// 用putString的方法保存数据
		editor.putInt("isfr", 0);
		
		editor.commit();
		getMyHandler=new getMyHandler();
		mHandler = new MyHandler();
		Log.e("11", "11");
		init(view);
		return view;
	}

	
	@Override
	public void onResume() {
		// TODO Auto-generated method stub
		Log.e("time", "onResume");
		
		
		
		if (App.getInfoNum.equals("0")||Integer.parseInt(App.getInfoNum)<0) {
			lrInfoShow.setVisibility(View.GONE);
			App.getInfoNum="0";
		}else {
			lrInfoShow.setVisibility(View.VISIBLE);
			tvInfoShow.setText("您有"+App.getInfoNum+"条信息未读>");
		}
		
		SharedPreferences sharedPreferences= activity.getSharedPreferences("pinglun", 
				Activity.MODE_PRIVATE); 
				// 使用getString方法获得value，注意第2个参数是value的默认值 
				
			
				int size =sharedPreferences.getInt("size", 1); 
			 if (size==1) {
				 int isfo =sharedPreferences.getInt("isfr", 0); 
				 if (isfo==1) {
						int  myuid =sharedPreferences.getInt("uid", 0); 
						int myposition =sharedPreferences.getInt("position", 0); 
						int myid =sharedPreferences.getInt("id", 0); 
						int mycid =sharedPreferences.getInt("cid", 0); 
						String mydetail =sharedPreferences.getString("detail", ""); 
						String mytime =sharedPreferences.getString("time", ""); 
						String myname =sharedPreferences.getString("name", ""); 
						String mydatetime =sharedPreferences.getString("datetime", ""); 
						String myrid =sharedPreferences.getString("rid", "");
						String myrname =sharedPreferences.getString("rname", "");
						String myruid =sharedPreferences.getString("ruid", "");
						
						CommentBean commentBean = new CommentBean();
						commentBean.id =myid;
						commentBean.cid = mycid;
						commentBean.uid = myuid;
						commentBean.detail = mydetail;
						commentBean.time = mytime;
						commentBean.name = myname;
						commentBean.datetime = mydatetime;
						commentBean.rid = myrid;
						commentBean.rname = myrname;
						commentBean.ruid = myruid;
					
//							circleBean.comment.get(myposition).add(commentBean);
							circleAdapter.setComm(myposition, commentBean);
						
//						circleAdapter.notifyDataSetChanged();
						Log.e(TAG, commentBean.toString());
						ProgressDialogBar.stopProgress();
					}
				    
					SharedPreferences myAhare =activity.getSharedPreferences("pinglun", Activity.MODE_PRIVATE);
					// 实例化SharedPreferences.Editor对象（第二步）
					SharedPreferences.Editor editor = myAhare.edit();
					// 用putString的方法保存数据
					editor.putInt("isfr", 0);
					
					editor.commit();
//					ProgressDialogBar.stopProgress();
			}
				
		
		super.onResume();
	}
	
	
	
	
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	private void init(View view) {
		mySingleton = MySingleton.getInstance(activity);
		circle_item_listView = (PullToRefreshListView) view.findViewById(R.id.circle_item_listView);
		circle_item_hint = (TextView) view.findViewById(R.id.circle_item_hint);
		lrInfoShow=(LinearLayout) view.findViewById(R.id.lr_info_show);
		tvInfoShow=(TextView) view.findViewById(R.id.tv_info_show);
		lrInfoShow.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent=new Intent(activity,MyinfoListActivity.class);
				startActivity(intent);
			}
		});
		
		info = AppTools.getDaString();
		MyAsynTask myAsynTask = new MyAsynTask();
		myAsynTask.execute();
		
		
		//circle_item_listView.onRefreshComplete();
		circle_item_listView.setOnRefreshListener(new OnRefreshListener2() {

			@Override
			public void onPullDownToRefresh(PullToRefreshBase refreshView) {
				circle_item_listView.getLoadingLayoutProxy(true,
						false).setLastUpdatedLabel("最近更新: "+ LotteryUtils.Long2DateStr_detail(System.currentTimeMillis()));
				//informations.clear();
				isToFirst=true;
				info = AppTools.getDaString();
				try {
					if (circleBean!=null) {
						if (circleBean.topic!=null) {
							if (circleBean.topic.size()!=0) {
								circleBean.topic.clear();
								circleBean.schemeinfo.clear();
							}
							circleAdapter.notifyDataSetChanged();
						}
						
					}
					
					
					
					
					MyAsynTask myAsynTask = new MyAsynTask();
					myAsynTask.execute();
					circle_item_listView.postDelayed(new Runnable() {
						
						@Override
						public void run() {
							
							circle_item_listView.onRefreshComplete();
						}
					}, 1000);
				} catch (Exception e) {
					// TODO: handle exception
				}
			
			}

			@Override
			public void onPullUpToRefresh(PullToRefreshBase refreshView) {
				// TODO Auto-generated method stub
				//MyToast.getToast(getActivity(), "最后一个").show();
				if (circleBean.topic!= null) {
				if (circleBean.topic.size()<10) {
					//MyToast.getToast(getActivity(), "这是最后一页了").show();
					
					circleAdapter.notifyDataSetChanged();
					circle_item_listView.postDelayed(new Runnable() {
						
						@Override
						public void run() {
							
							circle_item_listView.onRefreshComplete();
						}
					}, 1000);
				}else {
					
					info = circleBean.topic.get(9).datetime;
					
					circleAdapter.notifyDataSetChanged();
					mMyAsynTask = new MyAsynTask();
					mMyAsynTask.execute();
					circle_item_listView.postDelayed(new Runnable() {
						
						@Override
						public void run() {
							
							circle_item_listView.onRefreshComplete();
						}
					}, 1000);
					
				}
				}else {
					circleAdapter.notifyDataSetChanged();
					circle_item_listView.postDelayed(new Runnable() {
						
						@Override
						public void run() {
							circle_item_listView.onRefreshComplete();
						}
					}, 1000);
				}
				
			}
		});
		
//		circle_item_listView.setOnItemClickListener(new OnItemClickListener() {
//
//			@Override
//			public void onItemClick(AdapterView<?> arg0, View arg1, int position,
//					long arg3) {
//				
//				MyToast.getToast(getActivity(), position+"hang").show();
//				getInfoPosition=position-1;
//				GetMyAsynTask getMyAsynTask=new GetMyAsynTask();
//				getMyAsynTask.execute();
//			}
//		});
		
	}
private  String id;
	/*** 异步任务 用来后台获取数据 */
	class GetMyAsynTask extends AsyncTask<Void, Integer, String> {
		/**
		 * 在后台执行的程序
		 */
		@Override
		protected String doInBackground(Void... params) {
			getinfo = "{\"id\":" + circleAdapter.getTopicBeans().get(getInfoPosition).getSchemeid()+ "}";
			
			getopt = "15";
			Log.i("x", "投注接口 opt :" + getopt);
			Log.i("x", "投注方案详情  info  " + getinfo);

			// 加入验证后有问题,没有传key值
			getkey = App.key;
//			getimei = RspBodyBaseBean.getTime();
//			 getimei =RspBodyBaseBean.getIMEI(getActivity());;
			// Log.i("x", "投注方案详情 key " + key);
			id= circleAdapter.getTopicBeans().get(getInfoPosition).getUserid()+"";
			getcrc = RspBodyBaseBean.getCrc(gettime, getimei, getkey, getinfo, circleAdapter.getTopicBeans().get(getInfoPosition).getUserid()+"");
			// Log.i("x", "投注方案详情 crc " + crc);
			getauth = RspBodyBaseBean.getAuth(getcrc, gettime, getimei, circleAdapter.getTopicBeans().get(getInfoPosition).getUserid()+"");
			// Log.i("x", "投注方案详情=== auth " + auth);
			String[] values = { getopt, getauth, getinfo };
			String result = HttpUtils.doPost(App.names, values, App.path);

			Log.i("x", "得到投注内容   " + result);
			scheme = new Schemes();
			if ("-500".equals(result))
				return result;

			if (null == result)
				return "1";
//
			try {

				JSONObject item = new JSONObject(result);

				if ("0".equals(item.optString("error"))) {
					String schemeList = item.optString("schemeList");

					JSONArray array = new JSONArray(schemeList);

					JSONArray jsonArray2 = new JSONArray(array.toString());

					if (jsonArray2.length() == 0)
						return "1";
					// 如果取消了 则停止
					if (this.isCancelled()) {
						Log.i("x", "取消了异步。。。。");
						return null;
					}
					JSONObject items2 = array.getJSONObject(0);
					scheme.setId(items2.optString("id"));
					// 设置订单编号
//					String schemeNum = items2.optString("schemeNumber");
//					scheme.setSchemeNumber(schemeNum.equals("")
//							? LotteryUtils.getSchemeNum(AppTools.lottery.getLotteryID(), AppTools.lottery.getIsuseName(),  circleBean.topic.get(getInfoPosition).getSchemeid())
//							: schemeNum);
					scheme.setIsHide(items2.optInt("isHide"));
					scheme.setSecretMsg(items2.optString("secretMsg"));
					scheme.setAssureMoney(items2.optDouble("assureMoney"));
					scheme.setAssureShare(items2.optInt("assureShare"));
					scheme.setBuyed(items2.optString("buyed"));
					scheme.setInitiateName(items2.optString("initiateName"));
					scheme.setInitiateUserID(items2.optString("initiateUserID"));
					String isPurchasing = items2.optString("isPurchasing");
					if ("".equals(isPurchasing)) {
						isPurchasing = isJoin + "";
					}
					scheme.setIsPurchasing(isPurchasing);

//					// 设置订单期号
//					scheme.setIsuseID(AppTools.lottery.getIsuseId());
//					scheme.setIsuseName(AppTools.lottery.getIsuseName());

					scheme.setLevel(items2.optInt("level"));
					scheme.setLotteryID(items2.optString("lotteryID"));
					scheme.setLotteryName(items2.optString("lotteryName"));
					scheme.setLotteryNumber(items2.optString("lotteryNumber"));
					scheme.setMoney(items2.optInt("money"));
					scheme.setPlayTypeID(items2.optInt("playTypeID"));
					scheme.setPlayTypeName(items2.optString("playTypeName"));
					scheme.setQuashStatus(items2.optInt("quashStatus"));
					scheme.setRecordCount(items2.optInt("recordCount"));
					scheme.setSchedule(items2.optInt("schedule"));
					scheme.setSchemeBonusScale(items2.optDouble("schemeBonusScale"));
					scheme.setSchemeIsOpened(items2.optString("schemeIsOpened"));
					scheme.setSecrecyLevel(items2.optInt("secrecyLevel"));
					scheme.setSerialNumber(items2.optInt("serialNumber"));
					scheme.setShare(items2.optInt("share"));
					scheme.setShareMoney(items2.optInt("shareMoney"));
					scheme.setSurplusShare(items2.optInt("surplusShare"));
					scheme.setTitle(items2.optString("title"));
					scheme.setWinMoneyNoWithTax(items2.optDouble("winMoneyNoWithTax"));
					scheme.setWinNumber(items2.optString("winNumber"));

					// 设置订单下单时间
					scheme.setDateTime(LotteryUtils.getSchemeTime(System.currentTimeMillis()));

					scheme.setDescription(items2.optString("description"));
					scheme.setIsChase(items2.optInt("isChase"));
					scheme.setChaseTaskID(items2.optInt("chaseTaskID"));
					// 设置倍数
					scheme.setMultiple(App.bei);

					scheme.setFromClient(items2.optInt("fromClient"));
					scheme.setMyBuyMoney(item.optInt("myBuyMoney") + "");
					scheme.setMyBuyShare(item.optInt("myBuyShare"));
					String schemeStatus = "待出票";
					try {
						schemeStatus = items2.getString("schemeStatus");
					} catch (JSONException e) {
						// do nothing
					}
					scheme.setSchemeStatus(schemeStatus);

					JSONArray array_contents = new JSONArray(items2.optString("buyContent"));
					List<LotteryContent> contents = new ArrayList<LotteryContent>();
					LotteryContent lotteryContent;
					for (int k = 0; k < array_contents.length(); k++) {
						lotteryContent = new LotteryContent();
						try {
							JSONArray array2 = new JSONArray(array_contents.optString(k));

							lotteryContent.setLotteryNumber(array2.getJSONObject(0).optString("lotteryNumber"));
							lotteryContent.setPlayType(array2.getJSONObject(0).optString("playType"));
							lotteryContent.setSumMoney(array2.getJSONObject(0).optString("sumMoney"));
							lotteryContent.setSumNum(array2.getJSONObject(0).optString("sumNum"));
							contents.add(lotteryContent);
						} catch (Exception e) {
							JSONObject array2 = new JSONObject(array_contents.optString(k));

							lotteryContent.setLotteryNumber(array2.optString("lotteryNumber"));
							lotteryContent.setPlayType(array2.optString("playType"));
							lotteryContent.setSumMoney(array2.optString("sumMoney"));
							lotteryContent.setSumNum(array2.optString("sumNum"));
							contents.add(lotteryContent);
						}
					}
					scheme.setBuyContent(contents);

					if (this.isCancelled()) {
//						pd.dismiss();
						Log.i("x", "取消了异步。。。。");
						return null;
					}
					return "0";
				}
			} catch (Exception e) {
				Log.i("x", "myAllLottery 错误" + e.getMessage());
			}

			return "-1";
		}

		@Override
		protected void onPostExecute(String result) {
			if (null == result)
				return;
			if ("1".equals(result)) {
				getMyHandler.sendEmptyMessage(-1);
			}
			getMyHandler.sendEmptyMessage(Integer.parseInt(result));
			super.onPostExecute(result);
		}
	}
	/**
	 * 进行页面刷新
	 */
	@SuppressLint("HandlerLeak")
	class getMyHandler extends Handler {
		@Override
		public void handleMessage(Message msg) {
			if (pd != null) {
				pd.dismiss();
			}
			ProgressDialogBar.stopProgress();
			switch (msg.what) {
			case 0:
				Intent intent_info;
				if ("72".equals(scheme.getLotteryID()) || "73".equals(scheme.getLotteryID())
						|| "45".equals(scheme.getLotteryID())) {
					
					intent_info = new Intent(activity, MyCommonLotteryInfo_jc_other.class);
					App.scheme=scheme;
					intent_info.putExtra("scheme", scheme);
					intent_info.putExtra("id", id);
				} else {
					intent_info = new Intent(activity, MyCommonLotteryInfo_other.class);
					App.scheme=scheme;
					intent_info.putExtra("scheme", scheme);
					intent_info.putExtra("id", id);
				}
				startActivity(intent_info);
				break;
			default:
				break;
			case -1:
				MyToast.getToast(activity, "没有数据").show();
				break;
			case -500:
				MyToast.getToast(activity, "连接超时").show();
				break;
			}
			super.handleMessage(msg);
		}
	}
	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
	}
	

	
	
	class MyAsynTask extends AsyncTask<Integer, Integer, String> {
		
		String error = "-1";

		@Override
		protected String doInBackground(Integer... params) {
			
				opt = "86";
				time = RspBodyBaseBean.getTime();
				imei = RspBodyBaseBean.getIMEI(getActivity());
				//info = RspBodyBaseBean.change_TheSun(schemeId+"", context_Sun);
				
				// String key = MD5.md5(AppTools.user.getUserPass() + AppTools.MD5_key);
				String key = App.key;
				if (App.user==null) {
					crc = RspBodyBaseBean.getCrc(time, imei, key, info,
							"-1");
					auth = RspBodyBaseBean.getAuth(crc, time, imei, "-1");
				}else {
					crc = RspBodyBaseBean.getCrc(time, imei, key, info,
							App.user.getUid());
					auth = RspBodyBaseBean.getAuth(crc, time, imei, App.user.getUid());
				}
				
				String[] values = { opt, auth, info };
				Log.i(TAG, "晒单"+RequestParams.convertParams(getActivity(), opt, info));
				String result = HttpUtils.doPost(App.names, values,
						App.path);
				System.out.println("晒单：" + result);
				if ("-500".equals(result)){
					return "-500";
				}
					
				circleBean = new CircleBean();
				try {
					JSONObject jsonObject = new JSONObject(result);
					JSONArray topic = jsonObject.getJSONArray("topic");
					List<TopicBean> topicBeans = new ArrayList<CircleBean.TopicBean>();
					if (topic.equals("[]")) {
						error = "1";
					}
					for (int i = 0; i < topic.length(); i++) {
						
						JSONObject obj = topic.getJSONObject(i);
						TopicBean topicBean = new TopicBean();
						topicBean.id = obj.optInt("id");
						topicBean.userid = obj.optInt("userid");
						topicBean.detail = obj.optString("detail");
						topicBean.schemeid = obj.optInt("schemeid");
						topicBean.up = obj.optString("up");
						topicBean.datetime = obj.optString("datetime");
						topicBean.enable = obj.optBoolean("enable");
						topicBean.yjjj = obj.optString("yjjj");
						topicBean.stoptime = obj.getString("stoptime");
						topicBean.cancopy = obj.getBoolean("cancopy");
						topicBean.name = obj.optString("name");
						topicBean.HeadUrl = obj.optString("HeadUrl");
						topicBean.Wins = obj.optString("Wins");
						topicBean.iswin= obj.optString("iswin");
						topicBean.interest = obj.optString("interest");
						topicBean.PlayTypeID = obj.optString("PlayTypeID");
						topicBean.hb = obj.optString("hb");
						topicBean.follCount = obj.optString("follCount");
						topicBeans.add(topicBean);
					}
					JSONArray comment = jsonObject.getJSONArray("comment");
					List<List<CommentBean>> commentBeans = new ArrayList<List<CommentBean>>();
					
					for (int i = 0; i < comment.length(); i++) {
						JSONArray jsonArray = comment.getJSONArray(i);
						List<CommentBean> commentBeanlists = new ArrayList<CircleBean.CommentBean>();
						for (int j = 0; j < jsonArray.length(); j++) {
							JSONObject object2 = jsonArray.getJSONObject(j);
							CommentBean commentBean = new CommentBean();
							commentBean.id = object2.optInt("id");
							commentBean.cid = object2.optInt("cid");
							commentBean.uid = object2.optInt("uid");
							commentBean.detail = object2.optString("detail");
							commentBean.time = object2.optString("time");
							commentBean.name = object2.optString("name");
							commentBean.datetime = object2.optString("datetime");
							commentBean.rname = object2.optString("rname");
							commentBean.rid = object2.optString("rid");
							commentBean.ruid = object2.optString("ruid");
							commentBeanlists.add(commentBean);
						}
						commentBeans.add(commentBeanlists);
					}
					
					JSONArray schemeinfo = jsonObject.getJSONArray("schemeinfo");
					List<SchemeinfoBean> schemeinfoBeans = new ArrayList<CircleBean.SchemeinfoBean>();
					for (int i = 0; i < schemeinfo.length(); i++) {
						JSONObject object = schemeinfo.getJSONObject(i);
						SchemeinfoBean schemeinfoBean = new SchemeinfoBean();
						schemeinfoBean.buymoney = object.optString("buymoney");
						schemeinfoBean.buyTime = object.optString("buyTime");
						schemeinfoBean.preBetType = object.optString("preBetType");
						schemeinfoBean.isHide = object.optInt("isHide");
						schemeinfoBean.stopsellingtime = object.optString("stopsellingtime");
						schemeinfoBean.secretMsg = object.optString("secretMsg");
						schemeinfoBean.passTypeInfo = object.optString("passTypeInfo");
						//JSONArray optimization = object.getJSONArray("optimization");
						JSONArray InformationId = object.getJSONArray("informationId");
						informationIdBeans = new ArrayList<CircleBean.SchemeinfoBean.InformationIdBean>();
						for (int j = 0; j < InformationId.length(); j++) {
							JSONObject jsonObject2 = InformationId.getJSONObject(j);
							informationIdBean = new InformationIdBean();
							informationIdBean.ID = jsonObject2.optString("ID");
							informationIdBean.SchemeID = jsonObject2.optString("SchemeID");
							informationIdBean.PlayType = jsonObject2.optString("PlayType");
							informationIdBean.MatchNumber = jsonObject2.optString("MatchNumber");
							informationIdBean.Game = jsonObject2.optString("Game");
							informationIdBean.MaiTeam = jsonObject2.optString("MaiTeam");
							informationIdBean.GuestTeam = jsonObject2.optString("GuestTeam");
							informationIdBean.StopSelling = jsonObject2.optString("StopSelling");
							informationIdBean.LetBile = jsonObject2.optString("LetBile");
							informationIdBean.Score = jsonObject2.optString("Score");
							informationIdBean.Results = jsonObject2.optString("Results");
							informationIdBean.PassType = jsonObject2.optString("PassType");
							informationIdBean.issue = jsonObject2.optString("issue");
							informationIdBean.Status = jsonObject2.optString("Status");
							informationIdBean.EndTime = jsonObject2.optString("EndTime");
							informationIdBean.investContent = jsonObject2.optString("investContent");
							informationIdBean.Content = jsonObject2.optString("Content");
							informationIdBean.MainLoseball = jsonObject2.optString("MainLoseball");
							informationIdBean.LetScore = jsonObject2.optString("LetScore");
							informationIdBean.BigSmallScore = jsonObject2.optString("BigSmallScore");
							informationIdBean.strresult = jsonObject2.optString("strresult");
							informationIdBeans.add(informationIdBean);
							
						}
						schemeinfoBean.informationId = informationIdBeans;
						schemeinfoBeans.add(schemeinfoBean);
					}
					circleBean.comment = commentBeans;
					circleBean.topic = topicBeans;
					circleBean.schemeinfo = schemeinfoBeans;
					error = "0";
				} catch (JSONException e) {
					error = "-1";
					e.printStackTrace();
				}
			
			return error;
		}

		@Override
		protected void onPostExecute(String result) {
			circle_item_hint.setVisibility(View.GONE);
			circle_item_listView.setMode(Mode.BOTH);
			mHandler.sendEmptyMessage(Integer.parseInt(result));
			circle_item_listView.onRefreshComplete();
			super.onPostExecute(result);
		}
	}

	@SuppressLint("HandlerLeak")
	class MyHandler extends Handler  {
		@Override
		public void handleMessage(Message msg) {
			if (pd != null) {
				pd.dismiss();
			}
			try {
				ProgressDialogBar.stopProgress();
			} catch (Exception e) {
				// TODO: handle exception
			}
			
			switch (msg.what) {
			case 0:
				if(isToFirst){
					circleAdapter = new CircleAdapter(getActivity(), circleBean.topic, circleBean.schemeinfo,circleBean.comment);
					circle_item_listView.setAdapter(circleAdapter);
				}else{
					circleAdapter.addDate( circleBean.topic, circleBean.schemeinfo,circleBean.comment);
				}
				//circleAdapter.setDate(circleBean.topic, circleBean.schemeinfo,circleBean.comment);
				isToFirst=false;
			
				circleAdapter.notifyDataSetChanged();
				if (circleBean.topic.size() == 0) {
					circle_item_hint.setVisibility(View.VISIBLE);
					circle_item_hint.setText("没有更多数据");
					circle_item_listView.setMode(Mode.PULL_FROM_START);
				}
				//MyToast.getToast(context, "晒单成功").show();
				break;
			case 1:
				circle_item_hint.setVisibility(View.VISIBLE);
				circle_item_hint.setText("没有数据");
				//MyToast.getToast(context, "重复晒单").show();
				break;
			case -1:
				circle_item_hint.setVisibility(View.VISIBLE);
				circle_item_hint.setText("没有数据");
				break;
			case -500:
				circle_item_hint.setVisibility(View.VISIBLE);
				circle_item_hint.setText("网络异常，请重新打开网络");
				
				break;
			default:
				break;
			}
			super.handleMessage(msg);
		}

	
	}

	
	 

}
